package org.itboys.mobile.controller.mobile;


import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.entity.mongo.SundayAdvertisement;
import org.itboys.mobile.service.mongo.mobile.SundayMobileAdvertisementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 作者：jiangxiong
 * 日期：2017年2月9日
 * 联系方式 ：empty90911@126.com
 * 描述：圣代_广告（新闻，轮播图）_controller。
 * 
 */
@Controller
@RequestMapping("/sunday/mobile/advertisement")
public class SundayMobileAdvertisementController extends BaseController {


	@Autowired
	private SundayMobileAdvertisementService advertisementService;

	/**
	 * 广告信息HTML5（直接根据广告位获取）
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/html5ByZoneCode",method={ RequestMethod.POST, RequestMethod.GET} )
	@ApiOperation(value="根据广告位获取网页（例如：用户协议等），返回的是网页内容，直接加载")
	public  String html5ByZoneCode(HttpServletRequest request,
						 Model model,
						 @ApiParam(required=true, name="zoneKey", value="广告位key" +
								 "1，block_trade_protocol（区块链交易服务协议,）"
								 )@RequestParam(value = "zoneKey",required = true) String zoneKey
	){
		Map<String,Object> param = new HashMap<String,Object>();
		param.put("zoneKey",zoneKey);
		param.put("isDeleted",0);
		List<SundayAdvertisement> advertisements = advertisementService.list(param);
		if(ListUtil.isNotNull(advertisements)){
			model.addAttribute("advertisement",advertisements.get(0));
		}

		return "/sunday/advertisement/html5";
	}
}
